package controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pojo.Users;
import service.UsersService;
import util.CommonResult;

import javax.servlet.http.HttpSession;

@RestController
public class UsersController {
    @Autowired
    private UsersService usersService;

    @GetMapping("/userLogin")
    public CommonResult userLogin(@RequestParam String userName,
                                  @RequestParam String password,
                                  HttpSession session) {
        CommonResult result = usersService.userLogin(userName, password);
        Users users = (Users) result.getData();
        session.setAttribute("users", users);
        return result;
    }

    @RequestMapping("/userOut")
    public void userOut(@RequestParam("userId") String userId,
                        HttpSession session) {
        session.setAttribute(userId, null);
        System.out.println("用户:" + userId + "退出。。。");
    }

    @RequestMapping("/hello")
    public String hello() {
        return "hello";
    }
}
